﻿/// <reference path="../Ref/jquery-1.7.2-vsdoc.js" />
/// <reference path="wme.core.js" />

/* Side bar
/---------------------------------------*/
var wmeSidebar = function () {
    var sidebarShow = true;
    var easeSpeed = wmeCore.animationSpeed;

    init = function () {
        //Init panels
        $('.wme-layout-sidebar').removeClass('wme-sidebar-full').addClass('wme-sidebar-full');
        $('.wme-layout-main').removeClass('wme-main-contract').addClass('wme-main-contract');

        //Set up sidebar tiles
        $('.wme-layout-sidebar-tile').each(function () {
            var _this = $(this);
            var title = _this.find('.title-bar');
            //Size Height = 2/3 Width
            _this.height(_this.width() * 2 / 3)
            //Draggeable title bar
            title.draggable({
                opacity: 0.5,
                revert: 'invalid',
                appendTo: 'body',
                scroll: false,
                helper: function () {
                    $copy = _this.clone();
                    $copy.width(_this.width()).height(_this.height());
                    return $copy;
                }
            });
            //Config button
            _this.find('#btnTileConfig').click(function () {
                configPreviewTile(title.attr('wme-data-moduleid'));
            });
        });

        //Init scrollpane
        $('.wme-layout-sidebar-content').jScrollPane();

        //Button bindings
        $('#btnToggleSide').click(function () {
            toggleSidebar();
        });
        $('#btnSetting').click(function () {
            alert('Settings');
        });
        $('#btnInfo').click(function () {
            alert('Info');
        });
    };

    //Show/hide side bar
    toggleSidebar = function () {

        if (sidebarShow) {
            //Collapse side bar
            $('.wme-layout-sidebar').animate({
                width: 0
            }, easeSpeed, 'easeInExpo', function () {
                $(this).removeAttr('style').removeClass('wme-sidebar-full').addClass('wme-sidebar-contract');
                $('.wme-layout-sidebar-content').hide();
            });
            //Expand main
            $('.wme-layout-main').animate({
                width: '98%'
            }, easeSpeed, 'easeInExpo', function () {
                $(this).removeAttr('style').removeClass('wme-main-contract').addClass('wme-main-full');
            });
            //Button
            $('#btnToggleSide').rotate({
                angle: 0,
                animateTo: 180
            });
        }
        else {
            //Expand side bar
            $('.wme-layout-sidebar-content').show();
            $('.wme-layout-sidebar').animate({
                width: '18%'
            }, easeSpeed, 'easeInExpo', function () {
                $(this).removeAttr('style').removeClass('wme-sidebar-contract').addClass('wme-sidebar-full');
            });
            //Contract main
            $('.wme-layout-main').animate({
                width: '80%'
            }, easeSpeed, 'easeInExpo', function () {
                $(this).removeAttr('style').removeClass('wme-main-full').addClass('wme-main-contract');
            });
            //Button
            $('#btnToggleSide').rotate({
                angle: 180,
                animateTo: 0
            });
            //$('#btnToggleSide').removeClass('wme-flip-vertical');
        }
        sidebarShow = !sidebarShow;
    };

    configPreviewTile = function (tileId) {
        alert('TODO: Config for TileId: ' + tileId);
    };

    return {
        init: init,
        toggleSidebar: toggleSidebar
    }
} ();